package com.tupu.util;

import org.springframework.stereotype.Component;

import java.util.*;

/**
 * 图谱标签颜色生成
 */
@Component
public class LabelColorUtil {

    //固定颜色
    public static List<String> colorList() {
        String[] color = {"#F44336", "#F57636", "#E91E63", "#E81E1E", "#9C27B0", "#B02797", "#673AB7", "#923BB8",
                "#3F51B5", "#553FB5", "#2196F3", "#224FF2", "#03A9F4", "#0257F5", "#00BCD4", "#0074D4", "#009688", "#007396",
                "#4CAF50", "#4CB070", "#8BC34A", "#62C24A", "#CDDC39", "#95DB39", "#FFEB3B", "#D1FF3B"};
        List<String> list = new ArrayList<>();
        Collections.addAll(list, color);
        return list;
    }

    //随机生成颜色代码
    public static String getColor() {
        //红色
        String red;
        //绿色
        String green;
        //蓝色
        String blue;
        //生成随机对象
        Random random = new Random();
        //生成红色颜色代码
        red = Integer.toHexString(random.nextInt(256)).toUpperCase();
        //生成绿色颜色代码
        green = Integer.toHexString(random.nextInt(256)).toUpperCase();
        //生成蓝色颜色代码
        blue = Integer.toHexString(random.nextInt(256)).toUpperCase();
        //判断红色代码的位数
        red = red.length() == 1 ? "0" + red : red;
        //判断绿色代码的位数
        green = green.length() == 1 ? "0" + green : green;
        //判断蓝色代码的位数
        blue = blue.length() == 1 ? "0" + blue : blue;
        //生成十六进制颜色值
        String color = "#" + red + green + blue;
        return color;
    }
}